package com.jjsj.web.controller.mall;

import com.jjsj.common.annotation.Log;
import com.jjsj.common.core.controller.BaseController;
import com.jjsj.common.core.domain.AjaxResult;
import com.jjsj.common.core.page.TableDataInfo;
import com.jjsj.common.enums.BusinessType;
import com.jjsj.common.utils.poi.ExcelUtil;
import com.jjsj.mall.entity.MallSetting;
import com.jjsj.mall.service.IMallSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商城设置Controller
 *
 * @author www.jjsjshop.com
 * @date 2022-10-10
 */
@RestController
@RequestMapping("/mall/setting")
public class MallSettingController extends BaseController {
    @Autowired
    private IMallSettingService mallSettingService;

    /**
     * 查询商城设置列表
     */
    @PreAuthorize("@ss.hasPermi('mall:setting:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallSetting mallSetting) {
        startPage();
        List<MallSetting> list = mallSettingService.selectMallSettingList(mallSetting);
        return getDataTable(list);
    }

    /**
     * 导出商城设置列表
     */
    @PreAuthorize("@ss.hasPermi('mall:setting:export')")
    @Log(title = "商城设置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MallSetting mallSetting) {
        List<MallSetting> list = mallSettingService.selectMallSettingList(mallSetting);
        ExcelUtil<MallSetting> util = new ExcelUtil<MallSetting>(MallSetting.class);
        return util.exportExcel(list, "setting");
    }

    /**
     * 获取商城设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:setting:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(mallSettingService.selectMallSettingById(id));
    }

    /**
     * 新增商城设置
     */
    @PreAuthorize("@ss.hasPermi('mall:setting:add')")
    @Log(title = "商城设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallSetting mallSetting) {
        return toAjax(mallSettingService.insertMallSetting(mallSetting));
    }

    /**
     * 修改商城设置
     */
    @PreAuthorize("@ss.hasPermi('mall:setting:edit')")
    @Log(title = "商城设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallSetting mallSetting) {
        return toAjax(mallSettingService.updateMallSetting(mallSetting));
    }

    /**
     * 删除商城设置
     */
    @PreAuthorize("@ss.hasPermi('mall:setting:remove')")
    @Log(title = "商城设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mallSettingService.deleteMallSettingByIds(ids));
    }
}
